package ch.eureka.consumer.feign.controller;

import ch.eureka.consumer.feign.bean.User;
import ch.eureka.consumer.feign.service.HelloService;
import ch.eureka.consumer.feign.service.RefactorHelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ConsumerController {

    @Autowired
    private HelloService helloService;

    @Autowired
    private RefactorHelloService refactorHelloService;

    @RequestMapping(value = "/hello")
    public String hello(){
        return helloService.hello();
    }

    /**
     * 对于对象User，必须要有默认构造函数，否则会报错
     * @return
     */
    @RequestMapping(value = "/hello1")
    public String hello1(){

        System.out.println(helloService.hello1("你好"));
        System.out.println(helloService.hello2("你好", 11));
        System.out.println(helloService.hello3(new User(22, "构造User")));

        return helloService.hello();
    }

    /**
     * 对于对象User，必须要有默认构造函数，否则会报错
     * @return
     */
    @RequestMapping(value = "/refactor")
    public String hello2(){

        System.out.println(refactorHelloService.hello4("你好"));
        System.out.println(refactorHelloService.hello5("你好", 11));

        return "";
    }

    /**
     * 对象传递的好像都要用post，不然会报错
     * @param user
     * @return
     */
    @RequestMapping(value = "/refactor2", method = RequestMethod.POST)
    public String refactor2(@RequestBody ch.eureka.provider.api.bean.User user){
        return refactorHelloService.hello6(user);
    }
}
